package ajakuulauku;

public class Ball extends GameObject {
	
	/**
	 * The physics module associated with this specific Ball
	 */
	Physics physics;
	
	private double mass;
	private double friction;
	/**
	 * Knows whether the Ball is moving or not
	 */
	private boolean moving;
	
	
	public Ball() {
		this.setRadius(20);
		this.setImage("images/Ball-1.png");
		this.isMovable = true;
		this.isCollideable = true;
	}
	
	/**
	 * Constructor for a standard Ball
	 * @param X coordinate, double
	 * @param Y coordinate, double
	 * @param radius  double
	 * @param mass double
	 * @param f friction, double
	 */
	public Ball(double X, double Y, double radius, double mass) {
		this.setX(X);
		this.setY(Y);
		this.setRadius(radius);
		this.setImage("images/Ball-1.png");
		this.isMovable = true;
		this.isCollideable = true;
		
	}
	
	public void parseParam(String name, String value) {
		if(name == "mass") {
			mass = Double.parseDouble(value);
		}else if(name == "friction") {
			friction = Double.parseDouble(value);
		}else {
			super.parseParam(name, value);
		}
	}
	
	public void finishCreating() {
		// f = friction factor
		if (mass == 0) {
			mass = 1;
		}
		physics = new Physics(mass, friction);
	}
	
	/**
	 * Moves the ball
	 */
	public void Update() {
		Vector2 XY = this.physics.move(getX(), getY());
		if (XY.length() == 0) {
			this.moving = false;
		}
		else {
			this.moving = true;
		}
	}

	/**
	 * sets the Ball's moving state
	 * @param moving, boolean
	 */
	public void setMoving(boolean moving) {
		this.moving = moving;
	}

	/**
	 * gets the Ball's moving state
	 * @return Returns true if the ball is moving, otherwise false
	 */
	public boolean isMoving() {
		return moving;
	}
}
